package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.HouseListRespond;
import com.jiutong.meipengdai.entity.HousessRespond;
import com.jiutong.meipengdai.http.model.interfaces.HousessInfoBiz;
import com.jiutong.meipengdai.http.model.requests.HousessInfoRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 * Created by suxi on 2017/5/31.
 */

public class HousessInfoPresent {

    private final Context mContext;
    private final HousessInfoBiz mBaseBiz;
    private final HousessInfoRequest request;

    public HousessInfoPresent(Context context, HousessInfoBiz baseBiz){
        this.mContext = context;
        this.mBaseBiz = baseBiz;
        request = new HousessInfoRequest();
    }


    /**
     * 房产信息
     */
    public void getHouse(){
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<HouseListRespond>() {
            @Override
            public void onNext(HouseListRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("houseId",mBaseBiz.getHouseId());
        fieldsMap.put("mortgageStatus",mBaseBiz.getMortgageStatus());
        request.getHouse(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

    /**
     * 房产评估预览
     */
    public void getHousePingguPre(){
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<HousessRespond>() {
            @Override
            public void onNext(HousessRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("houseId", mBaseBiz.getHouseId());
        request.getHousePingguPre(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }
}
